package AsLayers.Tile
{
	import AsLayers.BaseType.Bounds;
	import AsLayers.BaseType.LonLat;
	import AsLayers.BaseType.Pixel;
	import AsLayers.BaseType.Size;
	
	import com.adobe.serialization.json.JSON;
	
	import mx.containers.Canvas;
	public class Feature extends Base
	{
		public var display:Canvas=new Canvas()
		public function Feature(position:Pixel, bounds:Bounds, size:Size)
		{
			super(position, bounds, size);
		}
		
		override public function destroy():void{
			super.destroy();
			this.display.parent.removeChild(this.display)
			this.display=null;
		}
		override public  function draw():void{
		   // trace(this.layer.getUrl(this.bounds))
		   this.display.x=this.position.x;
		   this.display.y=this.position.y;
		
		   this.display.move(this.position.x,this.position.y);
		   drawSomething();
		   var json:JSON
		   /*
		   var http:HTTPService=new HTTPService(this.layer.getUrl(this.bounds));
		   var httpResult=function(event:ResultEvent){
		   	  trace(event.result);
		   	  drawSomething();
		   }
		   var httpFault=function(){
		   	
		   }
		   http.addEventListener("result", httpResult);
           http.addEventListener("fault", httpFault);
           http.send();*/
           //this.display.source=this.layer.getUrl(this.bounds);
	    }
	    private function drawSomething():void{
	    	  
	    	var json:String='[{"shape":"POINT(120.185577324693 30.2619476409064)"},{"shape":"POINT(120.185465139594 30.2622669008202)"},{"shape":"POINT(120.186278163435 30.2610320544706)"},{"shape":"POINT(120.185721816791 30.260485871755)"},{"shape":"POINT(120.185297821054 30.2617859313075)"}]';
	    	var shapes=JSON.decode(json);
	    	this.display.graphics.beginFill(0xFFCC00);
	    	this.display.graphics.lineStyle(5,0x081721)
	    	for(var i in shapes){
	    		var shape:String=shapes[i].shape;
	    		var lonlat:String=shape.substring(6,shape.length-1);
	    		var lls=lonlat.split(" ");
	    		var px:Pixel=this.layer.getMap().getLayerPxFromLonLat(new LonLat(lls[0],lls[1]));
	    		trace(px);
	    		this.display.graphics.drawCircle(px.x-this.position.x,px.y-this.position.y,5);
	    		//this.layer.getMap().getLayerPxFromLonLat(
	    	}
	    	
	    	
			
			
	    	
	    	this.display.graphics.endFill()
	    }
	}
}